package com.qf.config;


import com.qianfeng.smsplatform.common.constants.RabbitMqConsants;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by jackiechan on 2020-02-26 16:05
 *
 * @Author jackiechan
 */
@Configuration
public class RabbitmqConfig {
    /**
     * 声明一个队列,防止我们发送消息的时候这个队列还不存在
     * true 代表持久化队列,会对队列中的消息进行持久化,防止程序崩溃的时候消息丢失
     * rabbitmq配置的第一件事是声明队列
     * @return
     */

    //并发的消费者数量 这里设置成单例
    public static final int DEFAULT_CONSUMER = 1;
    //每个消费者每次最大获取的信息条数
    public static final int DEFAULT_PREFETCHCOUNT = 50;

    @Bean
    public Queue preSendQueue() {
        return new Queue(RabbitMqConsants.TOPIC_PRE_SEND,true);
    }

    @Bean("taskContainerFactory")
    public SimpleRabbitListenerContainerFactory containerFactory(SimpleRabbitListenerContainerFactoryConfigurer factoryConfigurer, ConnectionFactory connectionFactory){
        SimpleRabbitListenerContainerFactory containerFactory=new SimpleRabbitListenerContainerFactory();
        containerFactory.setConcurrentConsumers(DEFAULT_CONSUMER);
        containerFactory.setPrefetchCount(DEFAULT_PREFETCHCOUNT);
        factoryConfigurer.configure(containerFactory, connectionFactory);
        return containerFactory;
    }

    //接下来写推送给接口模块的信息 告诉用户信息发送有没有成功
    //这里只在黑名单策略中写这个代码
    @Bean
    public Queue pushInterface(){
        return new Queue(RabbitMqConsants.TOPIC_PUSH_SMS_REPORT, true);
    }
}

